package com.wb.controller;

import com.wb.bean.user.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName ProvideOneController
 * @Description 提供者-1
 * @Author wangBo
 * @Date 2019/6/23 0023 上午 8:32
 * @Version 1.0
 */
@RestController(value = "provideOne")
public class ProvideOneController {

    private final Logger logger = LoggerFactory.getLogger(ProvideOneController.class);

    @RequestMapping(value = "/sendMsg", method = RequestMethod.POST)
    public String sendMsg(@RequestParam("id") Long id) {
        logger.info(" id : {}" , id);
        return "OK";
    }

//    @PreAuthorize("hasAuthority('admin')")     // 拥有权限
    @RequestMapping(value = "/sendMsg", method = RequestMethod.GET)
    public String getSecutiry() {

        OAuth2Authentication authentication = (OAuth2Authentication)SecurityContextHolder.getContext().getAuthentication();
        User user = (User)authentication.getPrincipal();
        logger.info("---------------    authentication : {} , user : {} " , authentication , null);
        return "OK";
    }

    @RequestMapping(value = "/sendMsg1", method = RequestMethod.GET)
    public String getSecutiry1(HttpServletRequest request) {
        logger.info(" header : {} " , request.getHeaderNames());
        return "OK";
    }
}